package huaabdelmartin;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.JOptionPane;

public class WriteOutPut {
	//instance variable
	private CreateReports reportObject;
	
    //constructor
	public WriteOutPut(CreateReports reportObject) {
	
		this.reportObject = reportObject;
	}

	//get and set
	
	public CreateReports getReportObject() {
		return reportObject;
	}
	public void setReportObject(CreateReports reportObject) {
		this.reportObject = reportObject;
	}
	
	/**
	 * Accesses the reportObject method to get a report String then writes it out to file
	 * @throws IOException
	 */
	public void writeExpensiveCheapJourneyReport(){
		//writes report to file then displays message saying the path to the report file
        String reportHolder = this.getReportObject().returnExpensiveCheapJourneyReport();

        //writes report to file
        try
        {    
            File myfile = new File("report1.txt");
            FileWriter writeReport = new FileWriter(myfile);
            writeReport.write(reportHolder);
            writeReport.close();
            StringBuffer writtenMessage = new StringBuffer();
            writtenMessage.append("Report written to ").append(myfile.getAbsolutePath());
            String wMess = writtenMessage.toString();
            JOptionPane.showMessageDialog(null, wMess);
            System.out.println(wMess);
        }
        catch(IOException ioexception)
        {
            ioexception.printStackTrace();
            System.exit(1);
        }
	}
	
	/**
	 * Accesses the reportObject method to get a report String then writes it out to file
	 * @throws IOException
	 */
	public void writeDriverDestinationsReport()
	{
		//writes report to file then displays message saying the path to the report file
		String reportHolder = this.getReportObject().returnDriverDestinationsReport();

        //writes report to file
        try
        {    
            File myfile = new File("report2.txt");
            FileWriter writeReport = new FileWriter(myfile);
            writeReport.write(reportHolder);
            writeReport.close();
            StringBuffer writtenMessage = new StringBuffer();
            writtenMessage.append("Report written to ").append(myfile.getAbsolutePath());
            String wMess = writtenMessage.toString();
            JOptionPane.showMessageDialog(null, wMess);
            System.out.println(wMess);
        }
        catch(IOException ioexception)
        {
            ioexception.printStackTrace();
            System.exit(1);
        }
	}
	
	/**
	 * Accesses the reportObject method to get a report String then writes it out to file
	 */
	public void writeDestination20142015Report(){
		//writes report to file then displays message saying the path to the report file
		String reportHolder = this.getReportObject().returnDestination20142015Report();

        //writes report to file
        try
        {    
            File myfile = new File("report3.txt");
            FileWriter writeReport = new FileWriter(myfile);
            writeReport.write(reportHolder);
            writeReport.close();
            StringBuffer writtenMessage = new StringBuffer();
            writtenMessage.append("Report written to ").append(myfile.getAbsolutePath());
            String wMess = writtenMessage.toString();
            JOptionPane.showMessageDialog(null, wMess);
            System.out.println(wMess);
        }
        catch(IOException ioexception)
        {
            ioexception.printStackTrace();
            System.exit(1);
        }
	}
}
